home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / maestro / source / quotemkr / openpane.c < prev    next >
Encoding:
Text File  |  1993-06-15  |  12.5 KB  |  297 lines

  1. /*
  2.  * Copyright (c) 1990, 1991, 1992 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and 
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that (i) the above copyright notices and this permission notice appear in
  7.  * all copies of the software and related documentation, and (ii) the name
  8.  * Stanford may not be used in any advertising or publicity relating to
  9.  * the software without the specific, prior written permission of
  10.  * Stanford.
  11.  * 
  12.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  13.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  14.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  15.  *
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  17.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
  18.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT
  19.  * ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY,
  20.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21.  * SOFTWARE.
  22.  */
  23.  
  24. /*$Header: /Source/Media/collab/QuoteMaker/RCS/openpanel.c,v 2.11 92/05/14 15:43:40 drapeau Exp $*/
  25. /* $Log:    openpanel.c,v $
  26.  * Revision 2.11  92/05/14  15:43:40  drapeau
  27.  * * Updated copyright information.
  28.  * 
  29.  * Revision 2.10  91/12/31  18:44:08  drapeau
  30.  * Moved the inclusion of string.h so that it does not create
  31.  * include file conflicts, especially with strings.h.
  32.  * 
  33.  * Revision 2.0  91/09/30  15:02:40  derek
  34.  * Version number changed to 2.0.
  35.  * 
  36.  * Revision 1.7  91/09/18  20:54:25  derek
  37.  * The Makefile is changed due to the changes made in the collab/ directory.
  38.  * 
  39.  * Revision 1.6  91/09/15  20:06:31  derek
  40.  * The following things are done:
  41.  * 1.      The foreground of mainTextPane and Quote Window are set to be black.
  42.  *         Also, the color of all the text fields are set to black.
  43.  * 2.      Now the quoted text will be shown directly on the Quote Window
  44.  *         when a panel-item selection is made.  The text will also be shown
  45.  *         while the author is highlighting a selection in the text window.
  46.  * 3.      The inconsistency problem regarding text selection is being taken
  47.  *         care of.  When the mouse cursor re-enters the text window,
  48.  *         the selection will be highlighted again.
  49.  * 4.      When the play button is pressed, the text currently selected
  50.  *         in the text window (rather than the text initially associated
  51.  *         with the edit) will be displayed.
  52.  * 5.      The name of the menu_option "Show Quote Window Specifications panel"
  53.  *         is shortened to be "Quote Window Options ..."
  54.  * 6.      A notify_interpose_destroy_func() is being added to fix the bug
  55.  *         that QuoteMaker might exit without killing the Quote Window (which
  56.  *         is also a base window).
  57.  * 7.      When a different font family or font style is selected, the change
  58.  *         will be automatically be reflected on the Quote Window (without the
  59.  *         need to "play" the edit in order to verify the font).  For font
  60.  *         size, the change will be reflected when either a return character is
  61.  *         entered at the text field or when one of those numeric "arrows"
  62.  *         are pressed.
  63.  * 8.      The play button will now flash when an edit is being played.
  64.  *         Pause button will also glow when playing is paused.
  65.  * 9.      In the course of playing, when another edit is selected,
  66.  *         the playing will be stopped.
  67.  * 10.     I have used Saber to clean up the code.
  68.  * 11.     The left-over "NewEditListPopUp" window is removed.
  69.  * 12.     The bug that when quote window is iconified, it wont be un-iconified
  70.  *         when the edit is played in timeline, is fixed.
  71.  * 13.     The DurationEstimate function is changed so that it no longer
  72.  *         needs an edit to be selected first.  It will take textWindowStart
  73.  *         and textWindowEnd directly as input parameters.
  74.  * 
  75.  * 
  76.  * 
  77.  * Revision 1.5  91/09/05  15:48:04  derek
  78.  * The following changes are made:
  79.  * 1.      The name "Quoted Text Window" has been changed to "Quote Window"
  80.  *         in the app.
  81.  * 2.      ShowApplication() and HideApplication() is changed because of the
  82.  *         the change of quote window from a popup to a basewindow.
  83.  * 3.      The QuitProc of QuoteMaker is fixed so that the quote window,
  84.  *         as a base window, will be destroyed separately.
  85.  * 4.      Now hitting return in the label field will not result in adding
  86.  *         a new edit.
  87.  * 5.      Copyright messages are included in front of every .h and .c file.
  88.  * 6.      The scrollbar and the footer of the Quote Window are hidden.
  89.  * 7.      I have changed the include openpanel.h statement in QuoteMaker.c
  90.  *         to include Browse.h.
  91.  * 8.      The delete bug corresponding to the change that the panel-list
  92.  *         must have a choice -- is fixed.  Also, the corresponding bug
  93.  *         for deleteAll is also fixed.
  94.  * 9.      Now, deleteAll and deletion of the last item in Panel_list
  95.  *         will cause the panel-list to be destroyed and a new one will
  96.  *         be created.
  97.  * 10.     GetOpt files have been removed from the directory.  Corresponding
  98.  *         changes are made.
  99.  * 11.     The start and end byte fields are removed from the main panel.
  100.  * 12.     I have put iconify, hide and show quote window to be buttons
  101.  *         instead of menu options.
  102.  * 13.     I have removed the PreviewPanelPopup and incorporated its features into
  103.  *         the main panel.  The three buttons:  pause, play and stop and
  104.  *         the DurationGauge are moved to the main panel.  But the
  105.  *         StatusMessage is removed.
  106.  * 14.     The EnableLocationChange and EnableSizeChange choice setting
  107.  *         are removed.  There are no longer such choices.
  108.  * 15.     Right now if a panel-item is selected and if another panel-item
  109.  *         is picked, the DeselectList() operation in the middle is
  110.  *         eliminated.  This operation involves updating of text fields and
  111.  *         messages and its removal speeds up the program.  The panel-list
  112.  *         must now take at least one choice.  (A choice must be selected
  113.  *         whenever there is at least one item on the list).  And now
  114.  *         there is no way to deselect a list by the user.
  115.  * 16.     The "modified bit" associated with the CurrentSelectionNumberLabel
  116.  *         is implemented.  Now, if a selection is picked, and if either
  117.  *         the quote window is moved or any text fields are changed, the
  118.  *         modified bit will be on.
  119.  * 17.     The Show-text-window button and the Show-quote-window-specifications-popup
  120.  *         button are removed.  They are now menu options under the Options Menu.
  121.  * 18.     The Modify button has its name changed to "Update Edit".
  122.  * 
  123.  * Revision 1.4  91/08/28  14:06:11  derek
  124.  * The following things are done:
  125.  * 1.    I have changed the NewEditList option to call the file browser
  126.  *     instead of giving a popup window.
  127.  * 2.    I ahve renamed all the options in the file menu so that they
  128.  *     are clearer and more informative.
  129.  * 3.    The documentFileType has been changed from "DTR" (which was
  130.  *     a copying fault :)) to "QuoteMaker".
  131.  * 4.    I ahve changed the stop button so that if it sees that 
  132.  *     HideQTWAfterPlayingEdit is true, stopplay will hide the window too.
  133.  * 5.    I have changed QuoteMaker.G (the interface) so that there is no
  134.  *     way to deselect a fontfamily and fontstyle item from the panel list
  135.  *     (ie. a choice is required.)
  136.  * 
  137.  * Revision 1.3  91/08/27  14:37:38  derek
  138.  * The following things are done:
  139.  * 1.    The QuotedTextWindow is changed from a base window to a popup window
  140.  *     (now it's called QuotedMaker_quotedTextBaseWindow).  I have also
  141.  *     added a few options: show, hide and iconify QTW and also created
  142.  *     an icon for QTW.
  143.  * 2.    The quoted text will be set in PerformSelection() instead of 
  144.  *     in SetSelection().
  145.  * 3.    I have changed the Document field and the EditList field of 
  146.  *     QuoteMaker so that they will display fill paths.
  147.  * 
  148.  * Revision 1.2  91/08/26  12:10:21  derek
  149.  * The following things are done:
  150.  * 1.    I have added a few notice_prompts to the linkProtocol (network)
  151.  *     functions to give warnings about invalid document names.
  152.  * 2.    The quoted text window will by default be hidden during "blank"
  153.  *     times. ie. when it is not displaying any text.  The interface has
  154.  *     been changed so that it now has a HideQuotedTExtWindowAfterPreview
  155.  *     check box.  The QuotedTextWindow will either stay on the screen
  156.  *     or be hidden as the author desires.
  157.  * 3.    Make the changes corresponding to the changing of name from OpenPanel
  158.  *     to Browse.
  159.  * 4.    The return value bug for OpenHandler, SaveHandler is fixed.
  160.  * 5.    I have changed the code so that Save and SaveAs will behave correctly.
  161.  *     The SaveAs PopUp/Open PopUp are removed.  Browse check is 
  162.  *     incorporated in the applications.
  163.  * 6.    The QuoteMaker file format has been changed.  An EditNumber field    
  164.  *     has been added.
  165.  * 7.    Changes corresponding to the return value by OpenDoc and SetSelection
  166.  *     are made.
  167.  * 8.    GetAppIcon() has been implemented.
  168.  * 9.    Fonts specified in the Edit-list will be preloaded in OpenDoc().
  169.  *     This will hopefully eliminate the startup delay needed to load
  170.  *     the font when we put text onto the Quoted TExt Window for the 
  171.  *     first time.
  172.  * 10.    The "play" button will now play things specified in the 
  173.  *     QuotedTExtWindowSpecificationsPopUp (instead of those specified
  174.  *     in the editList).
  175.  * 11.    The show selection button is replaced by the set selection button.
  176.  *     The Set Selection button willl now not only set the current
  177.  *     edit parameters but will also highlight the corresponding section
  178.  *     in the text.  Also, when one item on the panel-list is clicked on,
  179.  *     the corresponding segment in the text will also be highlighted.
  180.  * 12.    Notify events which tells the app to show the size and location 
  181.  *     of the Quoted Text Window are set up.  ie. those text-fields
  182.  *     on the interface will be updated instantaneously.
  183.  * 16.    editList.label is being sent across the network.
  184.  * 17.    The title bar and the footer of the QuotedTExtWindow are hidden.
  185.  * 
  186.  * Revision 1.1  91/08/13  22:52:39  derek
  187.  * Initial revision
  188.  *  */
  189. static char rcsid[] = "$Header: /Source/Media/collab/QuoteMaker/RCS/openpanel.c,v 2.11 92/05/14 15:43:40 drapeau Exp $";
  190.  
  191. #include <stdio.h>
  192. #include <sys/param.h>
  193. #include <sys/types.h>
  194. #include <xview/xview.h>
  195. #include <xview/panel.h>
  196. #include <xview/textsw.h>
  197. #include <xview/xv_xrect.h>
  198. #include <gdd.h>
  199. #include "QuoteMaker_ui.h"
  200. #include <sys/stat.h>
  201. #include <xview/font.h>
  202. #include <xview/notice.h>
  203. #include <xview/notify.h>
  204. #include <xview/server.h>          
  205. #include <xview/seln.h>            
  206. #include "Sender.h"
  207. #include "Receiver.h"
  208. #include "quoteMakerDefs.h"
  209. #include <Browse.h>
  210. #include <string.h>
  211.  
  212. void
  213.   InitBrowse()
  214. {
  215.   (void) CreateBrowse(OpenHandler,
  216.               SaveHandler,
  217.               QuoteMaker_baseWindow->baseWindow);
  218.   documentFirstLine = strdup("#QuoteMaker Edit Document#");
  219.   documentFileType = strdup("QuoteMaker");
  220. }
  221.  
  222.  
  223.  
  224. /*
  225.  *  This OpenHandler is called by Browse(), which in turn is invoked by
  226.  *  Menu_item Open(item, op).
  227.  */
  228. int
  229.   OpenHandler(proposedPath, id)
  230. char  *proposedPath;
  231. int   id;
  232. {
  233.   switch(id)
  234.   {
  235.    case IS_TEXTFILE:
  236.   {
  237.     int        result;
  238.     char    message [MAX_MESSAGE_LEN + 1];
  239.     struct stat    fileInfo;
  240.  
  241.     result = stat(proposedPath,&fileInfo);                /* Attempt to get info about the specified file */
  242.     if ((result == 0) && (!(fileInfo.st_mode & S_IFDIR)))        /* Does file exist (if so, is it *not* a directory)? */
  243.     {                                    /* Yes, the file exists; continue as normal */
  244.       if (unsavedChangesExist == YES)
  245.     GiveOneLastChanceToSave();
  246.       UnHighlightSelection();
  247.       DeselectList();
  248.       ResetCurrentSelection();
  249.       EmptyList();       
  250.       UpdateNumEditsMessage();
  251.       SetDocument(proposedPath);
  252.       Show(&QuoteMaker_textWindowPopup->textWindowPopup);
  253.       SetEditList("NoneSpecified");
  254.       untitledEditListNum ++;
  255.       unsavedChangesExist = NO;
  256.       return FILE_OK;
  257.     }
  258.     else
  259.     {
  260.       sprintf(message, "Cannot find '%s'.", proposedPath);
  261.       AlertByNoticePrompt(QuoteMaker_baseWindow->baseWindow, message);
  262.       return FILE_NOT_OK;
  263.     }
  264.   }
  265.  
  266.    case IS_EDITLIST:
  267.     return(ReadEditListFromFile(proposedPath, USER));
  268.    
  269.    default:
  270.     fprintf(stderr, "Unknown id value in OpenHandler.\n");
  271.     exit(0);
  272.  
  273.   }
  274. }
  275.  
  276.  
  277.  
  278. /*
  279.  *  This SaveHandler is called by Browse(), which in turn is invoked by
  280.  *  Menu_item Save(item, op).
  281.  */
  282. int
  283.   SaveHandler(proposedPath, id)
  284. char  *proposedPath;
  285. int   id;
  286. {
  287.   switch(id)
  288.   {
  289.    case IS_EDITLIST:
  290.     return(WriteEditListToFile(proposedPath, SAVE_AS));
  291.  
  292.    default:
  293.     fprintf(stderr, "Unknown id value in SaveHandler.\n");
  294.     exit(0);
  295.   }
  296. }
  297.